/*
 *   Copyright 2012, Thomas Kerber
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package milk.jpatch.code;

import java.io.Serializable;
import java.util.List;

import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.ConstantPoolGen;

/**
 * Container class for FieldInitCodeSegments.
 * @author Thomas Kerber
 * @version 1.1.0
 */
public class FieldInitCode implements Serializable{
    
    private static final long serialVersionUID = -3141938201078297156L;
    
    /**
     * The ficss of <init> methods.
     */
    private List<FieldInitCodeSegment> instanceFics;
    /**
     * The ficss of <cinit> methods.
     */
    private List<FieldInitCodeSegment> staticFics;
    
    /**
     * 
     * @param instanceFics The ficss of <init> methods.
     * @param staticFics The ficss of <cinit> methods.
     */
    public FieldInitCode(List<FieldInitCodeSegment> instanceFics,
            List<FieldInitCodeSegment> staticFics){
        this.instanceFics = instanceFics;
        this.staticFics = staticFics;
    }
    
    /**
     * 
     * @return The ficss of <init> methods.
     */
    public List<FieldInitCodeSegment> getInstanceFics(){
        return instanceFics;
    }
    
    /**
     * 
     * @return The ficss of <cinit> methods.
     */
    public List<FieldInitCodeSegment> getStaticFics(){
        return staticFics;
    }
    
    /**
     * Generates...
     * @param c The class to generate ficss from.
     * @return The fic.
     */
    public static FieldInitCode generate(JavaClass c){
        ConstantPoolGen cpg = new ConstantPoolGen(c.getConstantPool());
        return new FieldInitCode(
                FieldInitCodeSegment.generate(c.getMethods(), false, cpg),
                FieldInitCodeSegment.generate(c.getMethods(), true, cpg));
    }
    
}
